﻿@page "/gateway/variableruntime"
@namespace ThingsGateway.Gateway.Razor
@using System.Text.Json.Nodes
@using ThingsGateway.Admin.Application
@using ThingsGateway.Admin.Razor
@using ThingsGateway.Core.Json.Extension
@using ThingsGateway.Gateway.Application
@attribute [Authorize]
@attribute [RolePermission]
@inherits ComponentDefault


<div style="height: var(--table-height);padding: 2px 5px 10px 5px;">

    <AdminTable @ref=table TItem="VariableRunTime" AutoGenerateColumns="false" ShowAdvancedSearch=true
                AllowResizing="true" IsFixedHeader=true IsMultipleSelect=false SearchModel=SearchModel SearchMode=SearchMode.Top
                ShowExtendButtons=true ShowExportButton=false ShowExtendDeleteButton=false ShowExtendEditButton=false
                ShowDefaultButtons=false ExtendButtonColumnWidth=150 AutoRefreshInterval="10000" IsAutoRefresh
                OnQueryAsync="OnQueryAsync" IsPagination=true>
        <SearchTemplate>
            <div class="row form-inline g-2">
                <div class="col-12 col-md-6">
                    <Select IsVirtualize @bind-Value="context.DeviceName" Items="@CollectDeviceNames" ShowSearch="true" ShowLabel="true" IsClearable DisableItemChangedWhenFirstRender=true IsPopover />
                </div>
                <div class="col-12 col-md-6">
                    <BootstrapInput @bind-Value="context.Name" ShowLabel="true" />
                </div>
                <div class="col-12 col-md-6">
                    <BootstrapInput @bind-Value="context.RegisterAddress" ShowLabel="true" />
                </div>
            </div>
        </SearchTemplate>
        <TableColumns>
            <TableColumn @bind-Field="@context.DeviceName" ShowTips=true Filterable=true Sortable=true Visible=true />
            <TableColumn @bind-Field="@context.Name" ShowTips=true Filterable=true Sortable=true Visible=true />
            <TableColumn @bind-Field="@context.Description" ShowTips=true Filterable=true Sortable=true Visible=true />
            <TableColumn Field="@context.ChangeTime" ShowTips=true FieldExpression=@(()=>context.ChangeTime) Filterable=true Sortable=true Visible=true />
            <TableColumn Field="@context.CollectTime" ShowTips=true FieldExpression=@(()=>context.CollectTime) Filterable=true Sortable=true Visible=true />
            <TableColumn Field="@context.IsOnline" FieldExpression=@(()=>context.IsOnline) Filterable=true Sortable=true Visible=true />
            <TableColumn Field="@context.LastErrorMessage" ShowTips=true FieldExpression=@(()=>context.LastErrorMessage) Filterable=true Sortable=true Visible=true />

            <TableColumn Field="@context.LastSetValue" FieldExpression=@(()=>context.LastSetValue)  Visible=true ShowTips=true Formatter=@(JsonFormatter) />

            <TableColumn Field="@context.RawValue" FieldExpression=@(()=>context.RawValue)  Visible=true ShowTips=true Formatter=@(JsonFormatter) />
            <TableColumn Field="@context.Value" FieldExpression=@(()=>context.Value)  Visible=true ShowTips=true Formatter=@(JsonFormatter) />


            <TableColumn @bind-Field="@context.DataType" Filterable=true Sortable=true Visible=true />
            <TableColumn @bind-Field="@context.RegisterAddress" Filterable=true Sortable=true Visible=true />

            <TableColumn @bind-Field="@context.ProtectType" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.IntervalTime" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.OtherMethod" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.RpcWriteEnable" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.ReadExpressions" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.WriteExpressions" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.Unit" Filterable=true Sortable=true Visible="false" />

            <TableColumn @bind-Field="@context.Index" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.Id" Visible="false" DefaultSort=true DefaultSortOrder="SortOrder.Asc" />
            @* <TableColumn Field="@context.AlarmEnable" FieldExpression=@(()=>context.AlarmEnable) Filterable Sortable="false" Visible="false" />

            <TableColumn @bind-Field="@context.BoolOpenAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.BoolOpenRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.BoolOpenAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.BoolCloseAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.BoolCloseRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.BoolCloseAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HAlarmCode" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HHAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HHRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HHAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HHAlarmCode" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LAlarmCode" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LLAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LLRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LLAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LLAlarmCode" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.CustomAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.CustomRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.CustomAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.CustomAlarmCode" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.Remark1" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.Remark2" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.Remark3" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.Remark4" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.Remark5" Filterable Sortable="false" Visible="false" />  *@

        </TableColumns>
        <RowButtonTemplate>


            <PopConfirmButton IsShow=@AuthorizeButton("写入变量") Size="Size.ExtraSmall" Color="Color.Warning" Icon="fa-solid fa-bars" Text="@Localizer["WriteVariable"]" IsAsync OnConfirm="()=>OnWriteVariable(context)">

                <BodyTemplate>
                    <Textarea @bind-Value=WriteValue ShowLabel="true" ShowLabelTooltip="true" />
                </BodyTemplate>

            </PopConfirmButton>
        </RowButtonTemplate>
    </AdminTable>
</div>

@code {
    AdminTable<VariableRunTime> table;
}
